package com.itheima.Controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.LoginInfo;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录的Controller
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private EmpService empService;

    /**
     * 登录方法
     * @param emp
     * @return
     */
    @PostMapping
    public Result login(@RequestBody Emp emp){
//        1.接收参数

//        2.调用Service方法
        LoginInfo loginInfo = empService.login(emp);
//        3.根据返回值判断返回哪种Result
        if(loginInfo == null){
            return Result.error("用户名或密码错误");
        }
        return Result.success(loginInfo);
    }




}
